package cm.lock.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisClient {

    @Autowired
    private RedisTemplate redisTemplate;

    public void set(String key,Object value,Integer expiredTime){
        ValueOperations<String,Object> valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key,value);
        redisTemplate.expire(key,expiredTime, TimeUnit.SECONDS);
    }

    public void delete(String key){
        if (hasKey(key)){
            redisTemplate.delete(key);
        }

    }

    public Boolean hasKey(String key){
        return redisTemplate.hasKey(key);
    }


}
